package job.ali;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author wq
 */
public class Shuxingxing {
    private static int res=0;
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] nums=new int[n];

        for(int i=0;i<n;i++){
            nums[i]=scanner.nextInt();
        }

        List<Integer> list=new ArrayList<>();
        boolean flag[]=new boolean[n];
        new Shuxingxing().backtrack1(n,"",nums,flag);
        System.out.println(res);


    }


    public void backtrack1(int len,String s,int[] nums,boolean[] flag){
        if(s.length()==len){
            if(isValid(s,nums)){
                res++;
            }
            return;
        }

        for(int i=1;i<=len;i++){

            if(flag[i-1])
                continue;

            flag[i-1]=true;
            backtrack1(len,s+i,nums,flag);
            flag[i-1]=false;
        }
    }



   /* public void backtrack(int len,List list,int[] nums){
        if(list.size()==len){
            if(isValid(list,nums)){
                res=(res+1)%((int)(10e7+1));
            }
            return;
        }

        for(int i=1;i<=len;i++){

            if(list.contains(i))
                continue;
            list.add(i);
            backtrack(len,list,nums);
            list.remove(list.size()-1);
        }
    }*/

    private boolean isValid(String s,int[] nums) {
        for(int i=0;i<s.length();i++){
            if(nums[i]==s.charAt(i)-'0'){
                return false;
            }
        }
        return true;
    }
}

